package com.cungmua.app.task;

import android.content.Context;

import com.cungmua.app.handler.BaseAuthenticatedRequestHandler;
import com.cungmua.app.handler.ChangeSubcriptionHandler;
import com.cungmua.app.model.request.ChangeSubcriptionRequest;
import com.cungmua.app.model.response.ChangeSubcriptionResponse;
import com.cungmua.app.net.CungMuaAPI;

import retrofit.RetrofitError;

/**
 * Created by kelvin.nguyen on 8/1/14.
 */
public class ChangeSubcriptionTask extends AuthenticatedTask<ChangeSubcriptionRequest,Void,ChangeSubcriptionResponse> {
    private Context context;
    private ChangeSubcriptionHandler handler;

    public ChangeSubcriptionTask(Context context, ChangeSubcriptionHandler handler) {
        this.context = context;
        this.handler = handler;
    }

    @Override
    protected Context getContext() {
        return context;
    }

    @Override
    protected ChangeSubcriptionResponse doInBackground() throws RetrofitError {
        ChangeSubcriptionRequest request=params[0];

        return CungMuaAPI.getService().setCityPromotionEmails(request.toFieldMap());
    }

    @Override
    protected BaseAuthenticatedRequestHandler getHandler() {
        return handler;
    }

    @Override
    protected void onSuccess(ChangeSubcriptionResponse changeSubcriptionResponse) {
        handler.onConfirmSubcription(changeSubcriptionResponse);
    }
}
